function in_array(search,array){
    for(var i in array){
        if(array[i]==search){
            return true;
        }
    }
    return false;
}
function Text(direction,num){
    var Txt=$('.input'+num).val();
    var style=$('#style').val();
    style=Number(style);
    var con1 = Array(1,14,17,18,20,21,22,24);
    var con2 = Array(2,6);
    var con3 = Array(3,12,19);
    var con4 = Array(4,5,8,9,10,13,23);
    var con5 = Array(7,0);
    var con6 = Array(11,15,16);
    if(style==3){
        if(in_array(num,con1)){
            content1(Txt,num)
        }else if(in_array(num,con2)){
            content2(Txt,num)
        }else if(in_array(num,con3)){
            content3(Txt,num)
        }else if(in_array(num,con4)){
            content4(Txt,num)
        }else if(in_array(num,con5)){
        }else if(in_array(num,con6)){
            content6(Txt,num)
        }
    }
    else if(style==4){
    	 content1(Txt,num);
    }
    else{
        $('.text'+num).html(Txt);
    }

   // console.log(Txt,num);
    $('.input'+num).val('');
    savecontent(Txt,direction);
    $(".shade1").css('display','none');
	$(".In").css('display','none');
	$(".In").css('z-index','100');
    $(".shade").css('display','none');
        $('.text1').removeClass('text1-wh');
        $('.text2').removeClass('text2-wh');
        $('.text3').removeClass('text3-wh');
        $('.text4').removeClass('text4-wh');
        $('.text5').removeClass('text5-wh');
        $('.text6').removeClass('text6-wh');
        $('.text7').removeClass('text7-wh');

    $(".FunctionBar").css('display','block');
}
function qu(){
		$(".In").css('display','none');
		$(".shade1").css('display','none');
		$(".In").css('z-index','100');
}
function savecontent(Text,direction){
	var pbId = sessionStorage.getItem("pbId");
    var page=$('#current_page').val();
    // console.log(Text);
    console.log(Text,page,direction,pbId)
    	 $.ajax({
		    type:"POST",
		    url:"http://www.youyiku-yishu.cn/WebApp/AppPhotoBooks/saveTxt",
		    data:{page:page,pbId:pbId,Text:Text,direction:direction},
		    dataType:"json",
		       beforeSend: function (XMLHttpRequest) {
		         		XMLHttpRequest.setRequestHeader("DEVICEINFO", "JxRaZezavm3HXM3d9pWnYiqqQC1SJbsU");
		       }
		  }).then(data=>{
      
    })


}


var ROOT="http://www.youyiku-yishu.cn";
var pbId=$('#pbId').val();

 	/*
 	 * 上一页
 	 */

    $(".previous").click(function () {
       var page=$('#current_page').val();
       var allPage=$('#all_page').val();
       var Previous_Page=Number(page)-1;
       if(Previous_Page>=1){
           getPage(Previous_Page);
           $('#current_page').val(Previous_Page);
       }
              // change();
    })
	/*
	 * 下一页
	 */

	$(".next").click(function () {
        var page=$('#current_page').val();
        var allPage=$('#all_page').val();
        var Previous_Page=Number(page)+1;
        if(Previous_Page<=allPage){
            getPage(Previous_Page);
            $('#current_page').val(Previous_Page);
            $('.Span').html(Previous_Page);
            // $('.Span2').html(all_page);
        }
        // else{
        //     var pbId=$('#pbId').val();
        //     //若大于书的总页数,则需后台判断当前页是否有内容，若有内容则新增一页空白页，若无则无法再新增一页
        //     $.post(U('WebApp/PhotoBooks/whetherNewPage'),{page:Previous_Page,pbId:pbId},function(json) {
        //         // console.log(json,111);
        //         if(json.status==1){
        //             $('.Conter').html("");
        //             $('#current_page').val(Previous_Page);
        //             var allPage=$('#all_page').val(Previous_Page);
        //             $('.Span').html(Previous_Page);
        //             $('.Span2').html(Previous_Page);
        //         }
        //
        //
        //     })
        //
        //
        // }
         // change();
    })

/*
 *获取内页内容
 */
 	function getPage(page){
 		var ROOT='http://www.youyiku-yishu.cn';
 		var pbId = sessionStorage.getItem("pbId");
        $.ajax({
		    type:"POST",
		    url:"http://www.youyiku-yishu.cn/WebApp/AppPhotoBooks/getType",
		    data:{pbId:pbId,page:page},
		    dataType:"json",
		       beforeSend: function (XMLHttpRequest) {
		         		XMLHttpRequest.setRequestHeader("DEVICEINFO", "JxRaZezavm3HXM3d9pWnYiqqQC1SJbsU");
		       }
		  }).then(data=>{
		  
		  	var kind=data.kind;		
            if(kind==1){
               $.ajax({
		  			  type:"POST",
				   	  url:"http://www.youyiku-yishu.cn/WebApp/AppPhotoBooks/getOrdinal",
				      data:{pbId:pbId,page:page},
				      dataType:"json",
				       beforeSend: function (XMLHttpRequest) {
				         		XMLHttpRequest.setRequestHeader("DEVICEINFO", "JxRaZezavm3HXM3d9pWnYiqqQC1SJbsU");
				       }
				  }).then(data=>{
//                     console.log(data);
                 	   var ordinal=data.ordinal;//使用的模板页
                    $('#current_ordinal').val(ordinal)
                    // console.log(ordinal);
                    //根据模板页选择对应的模板
                    if (ordinal == 1) {
                         t1(page);
                    }
                    else if (ordinal == 2){
                        t2(page);
                    }
                    else if (ordinal == 3) {
                        t3(page);
                    }
                    else if (ordinal == 4) {
                        t4(page);
                    }
                    else if (ordinal == 5) {
                        t5(page);
                       
                    }
                    else if (ordinal == 6) {
                        t6(page);
                    }
                    else if (ordinal == 7) {
                        t7(page);
                    }
                    else if (ordinal == 8) {
                        t8(page);
                    }
                    else if (ordinal == 9) {
                        t9(page);
                    }
                    else if (ordinal == 10) {
                        t10(page);
                    }
                    else if (ordinal == 11) {
                        t11(page);
                    }
                    else if (ordinal == 12) {
                        t12(page);
                    }
                    else if (ordinal == 13) {
                        t13(page);
                    }
                    else if (ordinal == 14) {
                        t14(page);
                    }
                    else if (ordinal == 15) {
                        t15(page);
                    }
                    else if (ordinal == 16) {
                        t16(page);
                    }
                    else if (ordinal == 17) {
                        t17(page);
                    }
                    else if (ordinal == 18) {
                        t18(page);
                    }
                    else if (ordinal == 19) {
                        t19(page);
                    }
                    else if (ordinal == 20) {
                        t20(page);
                    }
                    else if (ordinal == 21) {
                        t21(page);
                    }
                    else if (ordinal == 22) {
                        t22(page);
                    }
                    else if (ordinal == 23) {
                        t23(page);
                    }
                    else if (ordinal == 24) {
                        t24(page);
                    }
                    else if (ordinal == 25) {
                        t25(page);
                    }
                    else if (ordinal == 26) {
                        t26(page);
                    }
                    else if (ordinal == 27) {
                        t27(page);
                    }
                    else if (ordinal == 28) {
                        t28(page);
                    }
                    else if (ordinal == 29) {
                        t29(page);
                    }
                    else if (ordinal == 30) {
                        t30(page);
                    }
                    else if (ordinal == 31) {
                        t31(page);
                    }
                    else if (ordinal == 32) {
                        t32(page);
                    }
                    else{

                        $('.Conter').html('');
                    }
                    tobecode();//语音地址转二维码
                })
            }else if (kind==2)
            {
            	 $.ajax({
				    type:"POST",
				    url:"http://www.youyiku-yishu.cn/WebApp/AppPhotoBooks/getInsert",
				    data:{page:page,pbId:pbId},
				    dataType:"json",
				       beforeSend: function (XMLHttpRequest) {
				         		XMLHttpRequest.setRequestHeader("DEVICEINFO", "JxRaZezavm3HXM3d9pWnYiqqQC1SJbsU");
				       }
				  }).then(json=>{
                    // console.log(json);
                    $('.Conter').html('');
                    var page="";
                    var img=json.img;
                    // page+='<div class="conter1">';
                    if(img.toString().indexOf("c1.jpg") > 0){
                        page += '<div class="iset1">';
                        page += '<img src="http://www.youyiku-yishu.cn/Apps/WebApp/View/default/images/photoNewBook/delete1.png"/ class="delete" onclick="deletePage()">';
                        page += '</div>';
                    }else if(img.toString().indexOf("c2.jpg") > 0){
                        page += '<div class="iset2">';
                        page += '<img src="http://www.youyiku-yishu.cn/Apps/WebApp/View/default/images/photoNewBook/delete1.png"/ class="delete" onclick="deletePage()">';
                        page += '</div>';
                    }else if(img.toString().indexOf("c3.jpg") > 0){
                        page += '<div class="iset3">';
                        page += '<img src="http://www.youyiku-yishu.cn/Apps/WebApp/View/default/images/photoNewBook/delete1.png"/ class="delete" onclick="deletePage()">';
                        page += '</div>';
                    }
                    $('.Conter').html(page);
                                    })


            }else if(kind==3)
            {
                Cha_4(page);
            }else if(kind==4)
            {
                Cha_5(page);
            }

                })
//		 })
    }             

                    //调出选择模板
                    $('.Func1').click(function(){
                        $('.Mould').css('display','inline');
                        $('.mouldpage').css('display','inline');
                    });
 	                //取消选择模板动作
                    $('.quxiao').click(function(){
                        $('.Mould').css('display','none');
                        $('.mouldpage').css('display','none');
                        var page=$('#current_page').val();
                        var num=$('#current_ordinal').val();
                        if(num==1){
                            t1(page);
                        }
                        else if(num==2){
                            t2(page);
                        }
                        else if(num==3){
                            t3(page);
                        }
                        else if(num==4){
                            t4(page);
                        }
                        else if(num==5){
                            t5(page);
                        }
                        else if(num==6){
                            t6(page);
                        }
                        else if(num==7){
                            t7(page);
                        }
                        else if(num==8){
                            t8(page);
                        }
                        else if(num==9){
                            t9(page);
                        }
                        else if(num==10){
                            t10(page);
                        }
                        else if(num==11){
                            t11(page);
                        }
                        else if(num==12){
                            t12(page);
                        }
                        else if(num==13){
                            t13(page);
                        }
                        else if(num==14){
                            t14(page);
                        }
                        else if(num==15){
                            t15(page);
                        }
                        else if(num==16){
                            t16(page);
                        }
                        else if(num==17){
                            t17(page);
                        }
                        else if(num==18){
                            t18(page);
                        }
                        else if(num==19){
                            t19(page);
                        }
                        else if(num==20){
                            t20(page);
                        }
                        else if(num==21){
                            t21(page);
                        }
                        else if(num==22){
                            t22(page);
                        }
                        else if(num==22){
                            t22(page);
                        }
                        else if(num==23){
                            t23(page);
                        }
                        else if(num==24){
                            t24(page);
                        }
                        else if(num==25){
                            t25(page);
                        }
                        else if(num==26){
                            t26(page);
                        }
                        else if(num==27){
                            t27(page);
                        }
                        else if(num==28){
                            t28(page);
                        }
                        else if(num==29){
                            t29(page);
                        }
                        else if(num==30){
                            t30(page);
                        }
                        else if(num==31){
                            t31(page);
                        }
                        else if(!num){
                            $('.Conter').html('');
                        }

                    });
                    //确认选择模板动作
                    $('.queren').click(function(){
                        $('.Mould').css('display','none');
                        $('.mouldpage').css('display','none');
                        savepage();
                        var page=$('#current_page').val();
                        var num=$('#ordinal').val();
                        $('#current_ordinal').val(num);
                        if(num==1){
                            t1(page);
                        }
                        else if(num==2){
                            t2(page);
                        }
                        else if(num==3){
                            t3(page);
                        }
                        else if(num==4){
                            t4(page);
                        }
                        else if(num==5){
                            t5(page);
                        }
                        else if(num==6){
                            t6(page);
                        }
                        else if(num==7){
                            t7(page);
                        }
                        else if(num==8){
                            t8(page);
                        }
                        else if(num==9){
                            t9(page);
                        }
                        else if(num==10){
                            t10(page);
                        }
                        else if(num==11){
                            t11(page);
                        }
                        else if(num==12){
                            t12(page);
                        }
                        else if(num==13){
                            t13(page);
                        }
                        else if(num==14){
                            t14(page);
                        }
                        else if(num==15){
                            t15(page);
                        }
                        else if(num==16){
                            t16(page);
                        }
                        else if(num==17){
                            t17(page);
                        }
                        else if(num==18){
                            t18(page);
                        }
                        else if(num==19){
                            t19(page);
                        }
                        else if(num==20){
                            t20(page);
                        }
                        else if(num==21){
                            t21(page);
                        }
                        else if(num==22){
                            t22(page);
                        }
                        else if(num==23){
                            t23(page);
                        }
                        else if(num==24){
                            t24(page);
                        }
                        else if(num==25){
                            t25(page);
                        }
                        else if(num==26){
                            t26(page);
                        }
                        else if(num==27){
                            t27(page);
                        }
                        else if(num==28){
                            t28(page);
                        }
                        else if(num==29){
                            t29(page);
                        }
                        else if(num==30){
                            t30(page);
                        }
                        else if(num==31){
                            t31(page);
                        }
                        else if(num==31){
                            t32(page);
                        }
                        $('#ordinal').val('');
                     });

                    $('.Mould').click(function(){
                        $('.Mould').css('display','none');
                        $('.mouldpage').css('display','none');
                        var page=$('#current_page').val();
                        var num=$('#ordinal').val();
                        if(num==1){
                            t1(page);
                        }
                        else if(num==2){
                            t2(page);
                        } 
                        else if(num==3){
                            t3(page);
                        }
                        else if(num==4){
                            t4(page);
                        }
                        else if(num==5){
                            t5(page);
                        }
                        else if(num==6){
                            t6(page);
                        }
                        else if(num==7){
                            t7(page);
                        }
                        else if(num==8){
                            t8(page);
                        }
                        else if(num==9){
                            t9(page);
                        }
                        else if(num==10){
                            t10(page);
                        }
                        else if(num==11){
                            t11(page);
                        }
                        else if(num==12){
                            t12(page);
                        }
                        else if(num==13){
                            t13(page);
                        }
                        else if(num==14){
                            t14(page);
                        }
                        else if(num==15){
                            t15(page);
                        }
                        else if(num==16){
                            t16(page);
                        }
                        else if(num==17){
                            t17(page);
                        }
                        else if(num==18){
                            t18(page);
                        }
                        else if(num==19){
                            t19(page);
                        }
                        else if(num==20){
                            t20(page);
                        }
                        else if(num==21){
                            t21(page);
                        }
                        else if(num==22){
                            t22(page);
                        }
                        else if(num==23){
                            t23(page);
                        }
                        else if(num==24){
                            t24(page);
                        }
                        else if(num==25){
                            t25(page);
                        }
                        else if(num==26){
                            t26(page);
                        }
                        else if(num==27){
                            t27(page);
                        }
                        else if(num==28){
                            t28(page);
                        }
                        else if(num==29){
                            t29(page);
                        }
                        else if(num==30){
                            t30(page);
                        }
                        else if(num==31){
                            t31(page);
                        }
                        else if(num==32){
                            t32(page);
                        }
                        $('#ordinal').val('');
                     });
               //点击选择模板动作
              function mb(num,parens){
                var master=$('#master').val();
                var pbId=sessionStorage.getItem("pbId");
                var page=$('#current_page').val();
               
                //检查权限
                $.ajax({
					    type:"POST",
					    url:"http://www.youyiku-yishu.cn/WebApp/AppPhotoBooks/checkPermissions",
					    data:{page:page,master:master,pbId:pbId},
					    dataType:"json",
					       beforeSend: function (XMLHttpRequest) {
					         		XMLHttpRequest.setRequestHeader("DEVICEINFO", "JxRaZezavm3HXM3d9pWnYiqqQC1SJbsU");
					       }
					  }).then(json=>{                 
                      // console.log(json);
                        if(json.status==1){
                            if(num==1){
                                var page=$('#current_page').val();
                                t1(page);
                                $('#ordinal').val(num);
                            }else if(num==2)
                            {
                                var page=$('#current_page').val();
                                t2(page);
                                $('#ordinal').val(num);
                            }
                            else if(num==3)
                            {
                                var page=$('#current_page').val();
                                t3(page);
                                $('#ordinal').val(num);
                            }
                            else if(num==4){
                                var page=$('#current_page').val();
                                t4(page);
                                $('#ordinal').val(num);
                            }
                            else if(num==5){
                                var page=$('#current_page').val();
                                t5(page);
                                $('#ordinal').val(num);
                            }
                            else if(num==6){
                                var page=$('#current_page').val();
                                t6(page);
                                $('#ordinal').val(num);

                            }else if(num==7){
                                var page=$('#current_page').val();
                                t7(page);
                                $('#ordinal').val(num);
                            }else if(num==8){
                                var page=$('#current_page').val();
                                t8(page);
                                $('#ordinal').val(num);
                            }
                            else if(num==9){
                                var page=$('#current_page').val();
                                t9(page);
                                $('#ordinal').val(num);
                            }
                            else if(num==10){
                                var page=$('#current_page').val();
                                t10(page);
                                $('#ordinal').val(num);
                            }
                            else if(num==11){
                                var page=$('#current_page').val();
                                t11(page);
                                $('#ordinal').val(num);
                            }
                            else if(num==12){
                                var page=$('#current_page').val();
                                t12(page);
                                $('#ordinal').val(num);
                            }
                            else if(num==13){
                                var page=$('#current_page').val();
                                t13(page);
                                $('#ordinal').val(num);
                            }
                            else if(num==14){
                                var page=$('#current_page').val();
                                t14(page);
                                $('#ordinal').val(num);
                            }
                            else if(num==15){
                                var page=$('#current_page').val();
                                t15(page);
                                $('#ordinal').val(num);
                            }
                            else if(num==16){
                                var page=$('#current_page').val();
                                t16(page);
                                $('#ordinal').val(num);
                            }
                            else if(num==17){
                                var page=$('#current_page').val();
                                t17(page);
                                $('#ordinal').val(num);
                            }
                            else if(num==18){
                                var page=$('#current_page').val();
                                t18(page);
                                $('#ordinal').val(num);
                            }
                            else if(num==19){
                                var page=$('#current_page').val();
                                t19(page);
                                $('#ordinal').val(num);
                            }
                            else if(num==20){
                                var page=$('#current_page').val();
                                t20(page);
                                $('#ordinal').val(num);
                            }
                            else if(num==21){
                                var page=$('#current_page').val();
                                t21(page);
                                $('#ordinal').val(num);
                            }
                            else if(num==22){
                                var page=$('#current_page').val();
                                t22(page);
                                $('#ordinal').val(num);
                            }
                            else if(num==23){
                                var page=$('#current_page').val();
                                t23(page);
                                $('#ordinal').val(num);
                            }
                            else if(num==24){
                                var page=$('#current_page').val();
                                t24(page);
                                $('#ordinal').val(num);
                            }
                            else if(num==25){
                                var page=$('#current_page').val();
                                t25(page);
                                $('#ordinal').val(num);
                            }
                            else if(num==26){
                                var page=$('#current_page').val();
                                t26(page);
                                $('#ordinal').val(num);
                            }
                            else if(num==27){
                                var page=$('#current_page').val();
                                t27(page);
                                $('#ordinal').val(num);
                            }
                            else if(num==28){
                                var page=$('#current_page').val();
                                t28(page);
                                $('#ordinal').val(num);
                            }
                            else if(num==29){
                                var page=$('#current_page').val();
                                t29(page);
                                $('#ordinal').val(num);
                            }
                            else if(num==30){
                                var page=$('#current_page').val();
                                t30(page);
                                $('#ordinal').val(num);
                            }
                            else if(num==31){
                                var page=$('#current_page').val();
                                t31(page);
                                $('#ordinal').val(num);
                            }
                            else if(num==32){
                                var page=$('#current_page').val();
                                t32(page);
                                $('#ordinal').val(num);
                            }
                        }
                        //没有权限
                        else{
                            wstMsg('您无此权限');
                        }



                  })




              }



						
					

                    //调出语音
                    function Version(num,text){
                    	$('#none_no').val(1);
                    	$('.num').val(num);
                    	$('.ranking').val(text);
						var data=$('.text'+num).attr('data');
						data=Number(data);
						//区分只能语音转二维码
						if(data==1){
							$('.fingerboard').css('display','none');
							$('.characters').css('display','none');
							$('.import').css('height','2.3rem')
						}else{
							$('.fingerboard').css('display','block');
							$('.characters').css('display','block');
								$('.import').css('height','4.3rem')
						}
						 $('.shade').css('display','block');
                            $('.import').css('display','block');
                            $('#voice').val(num);//文字位置
                            $('#text').val(text);//文字位置
                             $('.FunctionBar').css('display','none');
						
//                  	var remove=$('#remove').val();
//                  	    remove=Number(remove);
//                  	if(remove==0){
//                          $('.shade').css('display','block');
//                          $('.import').css('display','block');
//                          $('#voice').val(num);//文字位置
//                          $('#text').val(text);//文字位置
//                           $('.FunctionBar').css('display','none');
//                       
//						}
                    }                 
						
                    //键盘输入

                        $('.fingerboard').click(function(){
                            $('.import').css('display','none');
                         $('.input').css('display','inline');
                            $('.select').css('display','none');
                            $('.shade').css('display','none')
                    		$(".input").focus();
                    		 $('.shade1').css('display','inline');
                    		 $('.In').css('display','inline');
                    		 var num= $('#voice').val();
                    		 // console.log(num);
                    		     $('.In_'+num).css('z-index','200');
                    		 var content=$('.text'+num).text();
                    		 // console.log(content);
                            if(content){
                                if(content.indexOf('最多输入')<0){
                                    $('.input'+num).val(content);
                                }
                            }

                        })
                    
                    //语音取消事件

                        $('.cancel').click(function(){
                            $('.import').css('display','none');
                             $('.shade').css('display','none'); 
                              $('.FunctionBar').css('display','inline');
                        })
                          $('.shade').click(function(){
                          	 $('.shade').css('display','none');
                          	 $('.import').css('display','none');
                              $('.Uploadmode').css('display','none');
                              $('.Photolibrary1').css('display','none');
                              $('.voice1').css('display','none');
                              $('.FunctionBar').css('display','block');
                              $('.next').css('display','block');
                              $('.previous').css('display','block');
                              $('.stop').css('display','none');
							

                          });

                    //语音转文字
                    function Characters(type){
                        $('.import').css('display','none');
                        $('.voice_1').css('display','inline');
                        $('.yuyin').css('display','inline');
                        $('#type').val(type);
                        $(".FunctionBar").css('display','block');

                    }
                    //录音中
                     $('.yuyin').click(function(){
                     	 $('.yuyin').css('display','none');
                     	 $('.stop').css('display','inline');
                     	
                     	  
                     	 
                     });
                     //转换中
                     $('.stop').click(function(){
                     	 $('.stop').css('display','none');
                     	 $('.change').css('display','inline');
                     	 $('.voice1').css('display','none');
//                   	 $('.shade').css('display','none');
//						$('.none_no').css('display','block');
//                   	 warn6();
                     });
                     // 取消上传语音
                     $('.none_no').click(function(){
                     	$('.none_no').css('display','none');
                     	$('.shade').css('display','none');
                     	warn7();
                     	$('#none_no').val(0);
                     })
                    //语音转二维码
                    function Code(type){
                        $('.import').css('display','none');
                        // $('.voice').css('display','inline');
                        // $('.shade').css('display','none')
                        $('.voice_2').css('display','inline');
                        $('.yuyin').css('display','inline');
                        $('#type').val(type);
                    }
                    //调出上传栏事件

                  function renewal(direction,num){
                  	$('.shade').css('display','block')
                    $('.previous').css('display','none');
                      $('.next').css('display','none');
                  	// $('.img'+num+'>div>img').removeClass('mw1');
                    // $('.img'+num +'>div>img').removeClass('mw0');
                    // var transform=$('.img'+num).css('transform','none');
                    //   $('.img'+num).addClass('transform_5');
                      var flag=$('#flag').val();
                      flag=Number(flag);
                      if(flag==1){
                          wstMsg('温馨提示：上传视频建议在15秒内，避免长时间等待')
                          $('#flag').val(0);
                      }
						console.log(1111);
                    	      			$('#remove').val(1);
			                            $('.Uploadmode').css('display','inline');
                                         $('.FunctionBar').css('display','none');
			                            $('#direction').val(direction);
			                             $('.upload-div').css('display','inline');
			//                           $('.shade').css('display','inline')
			                            $('#imgbox').val(num);
			                           //  $('.upload-btn1').html('');
			                           // var page1='';
			                           // // page1+='<input type="file" name="" class="fileX" accept="image/png,image/gif,image/jpeg,image/bmp"">';
			                           // //  page1+='<input type="file" name="" class="fileX">';
			                           // $('.upload-btn1').html(page1);
			                           // var page2="";
			                           //     // page2+='<input type="file" name="" class="fileV" accept="audio/mp4, video/mp4" onchange="checkField()">';
			                           //     page2+='<input type="file" name="fileV" id="fileV" class="fileV ffff"  onchange="checkField()">';
                                        //     // page2+='<input type="file" id="file-input" name="fileContent" class="fileV">';//2018-11-12
			                           // $('.btnn').html(page2);
			                          
			                             $('.subsidiary').css('display','none');

                           		$('.img'+num+'> .upload-div').css('display','none');                   


                    	      $('.import').css('display','none');
                    }
               
                        $('.cancel1').click(function(){
 							$('.Uploadmode').css('display','none');
                             $('.shade').css('display','none')
                            // $('.fileX').remove();
                            // $('.fileV').remove();
                            $('#remove').val(0);
                             $('.subsidiary').css('display','block');			                
			                   $('.FunctionBar').css('display','block');
			                    $('.upload-div').css('display','none');
                        });
                    

                    /*
                     *图片库内容
                     */
                    function ToPhotolibrary(){                      
                            $('.Photolibrary').css('display','inline');
                            $('.shade').css('display','inline');
                            $('.Uploadmode').css('display','none');
                           var pbId=sessionStorage.getItem("pbId");
                           var userId=sessionStorage.getItem('userId');
                           console.log(pbId,userId)
						     $.ajax({
								    type:"POST",
								    url:"http://www.youyiku-yishu.cn/WebApp/AppPhotoBooks/PicDepot",
								    data:{pbId:pbId,userId:userId},
								    dataType:"json",
								       beforeSend: function (XMLHttpRequest) {
								         		XMLHttpRequest.setRequestHeader("DEVICEINFO", "JxRaZezavm3HXM3d9pWnYiqqQC1SJbsU");
								       }
								  }).then(data=>{

                                   console.log(data);
                                $('.Images').html()
                                var depot="";

                                for (var i=0;i<data.length;i++){
                                    depot+='<div class="i1 imgboxx'+i+'">';
                                    var img1=data[i].img;
                                    var flg='_thumb';
                                    var img2=insert_flg(img1,flg,37);
                                    var img1="";
                                    depot+='<img src="'+ROOT+'/'+img2+'" class="s1 imgdepot'+i+'" onclick="upload('+i+','+data[i].photoId+')"/>';
                                    depot+='<img src="'+ROOT+'/Apps/WebApp/View/default/images/photoNewBook/ridus.png" class="ridus"/>';
                                    depot+='<img src="'+ROOT+'/Apps/WebApp/View/default/images/photoNewBook/gou.png" class="gou sure'+i+'"/>';
                                    depot+='</div>';

                                    }
                                $('.Images').html(depot);
                                // alert(depot)
                            })

                            $('.shade').click(function(){
                                $('.shade').css('display','none')
                                $('.Photolibrary').css('display','none')


                            });
							$('#remove').val(0);
                      
                    }
                    function Tocellphone(){
                        $('.btn5').click(function(){
                            $('.Uploadmode').css('display','none');
                        })
                    }
                    //图片选中的事件
                    function upload(i,photoId){
                        $('.imgboxx'+i).click(function(){
                            $('.gou').css('display','none');
                            $('.sure'+i).css('display','inline');
                            var src=$('.imgdepot'+i).attr('src');
                            $('#imgdepot').val(src);
                            $('#photoId').val(photoId);
                            // console.log(src);
                        })
                    }


                    function savepage(){
                    	var pbId = sessionStorage.getItem("pbId");
                        var page=$("#current_page").val();
                        var ordinal=$('#ordinal').val();
                        var master=$('#master').val();
                        console.log(page,ordinal,master);
                        // alert(ordinal);
                        if(ordinal){
                        	$.ajax({
							    type:"POST",
							    url:"http://www.youyiku-yishu.cn/WebApp/AppPhotoBooks/savePage",
							    data:{page:page,pbId:pbId,ordinal:ordinal,master:master},
							    dataType:"json",
							       beforeSend: function (XMLHttpRequest) {
							         		XMLHttpRequest.setRequestHeader("DEVICEINFO", "JxRaZezavm3HXM3d9pWnYiqqQC1SJbsU");
							       }
							  }).then(data=>{
                                   console.log(data)
                            })
                        }
                        }


                    /*
                     *微信开始语音接口
                     */
                    function startRecord(){

                        wx.startRecord();

                    }

                    /*
                     *微信停止语音接口
                     */
                    function stopRecord(){
                        wx.stopRecord({
                            success: function (res) {
                                var localId = res.localId;
                                var type=$('#type').val();
                                if(type==1){
                                    translateVoice(localId)
                                }else if (type==2){
                                    uploadVoice(localId)
                                }

//                              $('.voice').css('display','none');

                            }
                        });
                        $('.change').css('display','none');
                      	$('.shade').css('display','none');
                      	$('.voice1').css('display','none');
                      	
                    }

                    /*
                     *微信识别语音接口
                     */
                    function translateVoice(localId){

                        wx.translateVoice({
                            localId: localId, // 需要识别的音频的本地Id，由录音相关接口获得
                            isShowProgressTips: 1, // 默认为1，显示进度提示
                            success: function (res) {
                                // alert(res.translateResult); // 语音识别的结果
                                var num = $('#voice').val();
                                var direction = $('#text').val();
                                $('.text'+num).html(res.translateResult);
                                $page=$('#current_page').val();
                                var Text=res.translateResult;
                                $.post(U('WebApp/PhotoBooks/saveTxt'),{page:$page,pbId:pbId,Text:Text,direction:direction},function(json){
                                    var con1 = Array(1,14,17,18,20,21,22,24);
                                    var con2 = Array(2,6);
                                    var con3 = Array(3,12,19);
                                    var con4 = Array(4,5,8,9,10,13,23);
                                    var con5 = Array(7,0);
                                    var con6 = Array(11,15,16);
                                    if(in_array(num,con1)){
                                        content1(Text,num)
                                    }else if(in_array(num,con2)){
                                        content2(Text,num)
                                    }else if(in_array(num,con3)){
                                        content3(Text,num)
                                    }else if(in_array(num,con4)){
                                        content4(Text,num)
                                    }else if(in_array(num,con5)){
                                        content5(Text,num)
                                    }else if(in_array(num,con6)){
                                        content6(Text,num)
                                    }
                                })
                            }
                        });

                    }







                    /*
                     *微信上传语音
                     */
                    function uploadVoice(url){                    
                                var serverId = res.serverId; // 返回音频的服务器端ID
                                var page=$('#current_page').val();
                                var direction = $('#text').val();
                                var num = $('#voice').val();
                                // alert(num);alert(direction);
                                $.post(Think.U('WebApp/PhotoBooks/saveVideo'),{url:url,pbId:pbId,page:page,direction:direction},function(json){
                                    // alert(JSON.stringify(json))
                                        if(json.status==1){
                                            var page="";
                                                page+='<div class="erWeiMa" data-url="'+url+'"></div>'
                                            $('.text'+num).html(page);
                                            tobecode();
                                        }else{
                                            wstMsg('保存语音失败，请重试');
                                        }



                                })                                                 
                    }

                    $('.FUNC').click(function(){
                        var master=$('#master').val();
                        if(master==0){
                            wstMsg('您无此权限');
                        }else{
                            $('.Photolibrary1').css('display','inline');
                            $('.shade').css('display','inline');
                        }

                    })
                    $('.NO').click(function(){
                        $('.Photolibrary').css('display','none');
                        	$('.shade').css('display','none');
                            $('#photoId').val("");
                             $('.FunctionBar').css('display','block');
                        $('.previous').css('display','block');
                        $('.next').css('display','block');
                            
                    })
                    /*
                     *保存图片库的图片
                     */
                    $('.OK').click(function(){
                        var src=$("#imgdepot").val();
                        var photoId=$("#photoId").val();
                        var direction=$('#direction').val();
                        var pbId = sessionStorage.getItem("pbId");
                        var page=$("#current_page").val();
                        var num=$('#imgbox').val();
                        console.log(src,photoId,direction,pbId,page,num)
                         $.ajax({
								    type:"POST",
								    url:"http://www.youyiku-yishu.cn/WebApp/AppPhotoBooks/saveDepotImg",
								    data:{photoId:photoId,pbId:pbId,page:page,direction:direction},
								    dataType:"json",
								       beforeSend: function (XMLHttpRequest) {
								         		XMLHttpRequest.setRequestHeader("DEVICEINFO", "JxRaZezavm3HXM3d9pWnYiqqQC1SJbsU");
								       }
								  }).then(json=>{
								  	console.log(json);
                            if(json.status==1){
                                $('.img'+num).html();
                                var page="";
                                var img1=json.img;
                                var appearance=json.appearance;
                                var flg='_thumb';
                                var ROOT="http://www.youyiku-yishu.cn";
                                var img2=insert_flg(img1,flg,37);
                              	appearance=Number(appearance);
                                if(appearance==0 || appearance==2){
                                	  page+='<img src="' + ROOT + '/'+img2+'" onclick="class="appearance'+appearance+' targetObj_1" id=""style="width:100%">';
                                }else{
                                	page+='<img src="' + ROOT + '/'+img2+'" onclick="class="appearance'+appearance+' targetObj_1" id=""style="height:100%">';
                                }
                              
                                $('.img'+num).html(page);
                                $("#imgdepot").val('');$("#photoId").val('');$("#direction").val('');
                                $('.Photolibrary').css('display','none');
                                $('.shade').css('display','none');
                                $('.previous').css('display','block');
                                $('.next').css('display','block');
                            }
						
                        })

						  $('.FunctionBar').css('display','block');
                    })
                    //选择插页
                    $('.PhotoImg1').click(function(){
                        $('.PhotoImg1').addClass('PhotoImg');
                        $('.PhotoImg2').removeClass('PhotoImg');
                    })
                    $('.PhotoImg2').click(function(){
                        $('.PhotoImg2').addClass('PhotoImg');
                        $('.PhotoImg1').removeClass('PhotoImg');
                    })
                    //选择插画
                    function chooseInsert(i) {
                        $('#insert').val(i);
                    }
                    function otherInsert(i) {
                        $('#insert').val(i);
                    }
                    $('.Conter').click(function(){
                        $('.Photolibrary1').css('display','none');
                    })
                    //点击插页取消的事件
                    $('.NO1').click(function(){
                        $('.shade').css('display','none')
                        $('.Photolibrary1').css('display','none');

                    })
                    /*
                     *选择插页方法
                     */
                    function chooseinsets(num,type){
                        $('#insert').val(num);
                        $('#formwork').val(type);
                    }


                    /*
                     *保存插页
                     */
                    $('.OK1').click(function(){
                    	
                        var pbId=sessionStorage.getItem("pbId");//书本id
                        var insert=$('#insert').val();//插页id
                        var formwork=$('#formwork').val();//插页类型,1:普通页，2：普通插页，3：语音页，4：图片页
                        var page = $("#current_page").val();//当前页码
                        var style=$('#style').val();//风格
                        console.log(pbId,insert,formwork,page,style);
                        insert=Number(insert);
                        formwork=Number(formwork);
                        // console.log(formwork,page,pbId,insert);
                        //假如是模板插页或是语音，图片插页
                        if(formwork==1 || formwork==3 ||formwork==4){
                        	$.ajax({
								    type:"POST",
								    url:"http://www.youyiku-yishu.cn/WebApp/AppPhotoBooks/otherInsert",
								    data:{pbId: pbId, page: page,kind:formwork,ordinal:insert},
								    dataType:"json",
								       beforeSend: function (XMLHttpRequest) {
								         		XMLHttpRequest.setRequestHeader("DEVICEINFO", "JxRaZezavm3HXM3d9pWnYiqqQC1SJbsU");
								       }
								  }).then(json=>{                        	                        	                                                                     
                                if (json.status == 1) {
                                    $('current_page').val(json.page);
                                    $('.Conter').html('');

                                    $('#insert').val('');
                                    var currentPage=$("#current_page").val();
                                    var totalPage=$('#all_page').val();
                                    //若当前页为空白页
                                    if(json.isempty==1){
                                        var nextPage=Number(currentPage);
                                        var allpage=Number(totalPage);
                                    }else{
                                        var nextPage=Number(currentPage)+1;
                                        var allpage=Number(totalPage)+1;
                                    }
                                    getPage(nextPage);
                                    $('.Span').text(nextPage);
                                    $('#current_page').val(nextPage);
                                    $('.Span2').text(allpage);
                                    $('#all_page').val(allpage);
                                }
                            })


                        }else if(formwork==2){
                            var style=$('#style').val();
                            if(style==1){
                                var src = 'Apps/WebApp/View/default/images/photoNewBook/parentOffspring/c' + insert + '.jpg';
                            }else if(style==2){
                                var src = 'Apps/WebApp/View/default/images/photoNewBook/fresh/c' + insert + '.jpg';
                            }else if(style==3){
                            	 var src = 'Apps/WebApp/View/default/images/photoNewBook/concise/c' + insert + '.jpg';
                            }else if(style==4){
                            	 var src = 'Apps/WebApp/View/default/images/photoNewBook/delicacy/c' + insert + '.jpg';
                            }
                            $.ajax({
								    type:"POST",
								    url:"http://www.youyiku-yishu.cn/WebApp/AppPhotoBooks/chooseInsert",
								    data:{src: src, pbId: pbId, page: page},
								    dataType:"json",
								       beforeSend: function (XMLHttpRequest) {
								         		XMLHttpRequest.setRequestHeader("DEVICEINFO", "JxRaZezavm3HXM3d9pWnYiqqQC1SJbsU");
								       }
								  }).then(json=>{                                                                                
                                if (json.status == 1) {
                                    $('current_page').val(json.page);
                                    $('.Conter').html('');
                                    i=$('#insert').val('');
                                    var currentPage=$("#current_page").val();
                                    var totalPage=$('#all_page').val();
                                    //若当前页为空白页
                                    if(json.isempty==1){
                                        var nextPage=Number(currentPage);
                                        var allpage=Number(totalPage);
                                    }else{
                                        var nextPage=Number(currentPage)+1;
                                        var allpage=Number(totalPage)+1;
                                    }
                                    getPage(nextPage);
                                    $('.Span').text(nextPage);
                                    $('#current_page').val(nextPage);
                                    $('.Span2').text(allpage);
                                    $('#all_page').val(allpage);
                                }


                            })


                        }
                        $('.Photolibrary1').css('display','none');
                        $('.shade').css('display','none');
                    })


$(function(){
	
	
	
	

/*
 *判断是否有第一页，若有则加载数据，没有则当前页为第一页(控制页码)
 */
    var page=$('#current_page').val();//获取当前页码
    page=Number(page);
    if(page!=0){
        getPage(1);
    }else{
        $('#current_page').val(1);
    }
	var current_page=$('#current_page').val();
	$('.Span').html(current_page);
	var all_page=$('#all_page').val();
	$('.Span2').html(all_page);

    var span=$('.Span2').html();
    $('#edit-tto-airtempcontrol').attr("max",span);

/*
 *是否显示提示
 */
//查看真正的页数，若内容为空则显示背景图
    var realPage=$('#realPage').val();
    // console.log(realPage);
    if(realPage==0){
        $('.point').css('display','block');
        $('.shade3').css('display','block');

    }
/*
 *关闭提示信息
 */
$('body').click(function(){
    $('.point').css('display','none');
    $('.shade3').css('display','none');
    })

$('.point').click(function(){
    $('.point').css('display','none');
    $('.shade3').css('display','none');
    })

$('.shade3').click(function(){
    $('.point').css('display','none');
    $('.shade3').css('display','none');
})

/*
 *判读手机类型，调用不同的上传图片方式
 */
    var u = navigator.userAgent;
    //苹果手机

    if (u.indexOf('iPhone') > -1) {

    }
    //安卓系统
    else{
        $('.FunctionBar').addClass('ios');
    }
  
    var syncUpload = function(localIds){

        var localId = localIds.pop();
         wx.uploadImage({
            localId: localId.toString(),
            isShowProgressTips: 1,
            success: function (res) {
                var serverId = res.serverId; // 返回图片的服务器端ID
                // alert(localId);
               // 其他对serverId做处理的代码
                //判断是否为iso系统
                //
                // testLoad(localId);

                    var access=$('#accessToken').val();

                    $.ajax({
                        type:'POST',
                        url:'http://www.youyiku-yishu.cn/WechatUpload.php',
                        // url: U('WebApp/PhotoBooks/weChatUpload'),
                        data: {'media_id':serverId,'access':access},
                        dataType:'json',
                        success: function (data) {
                            // alert(JSON.stringify(data));
                            if(data.status==1){
                                var url=data.filepath;
                                var pbId=$('#pbId').val();
                                // console.log(pbId)
                                $.post(U('WebApp/PhotoBooks/uploadToImgDepot'),{pbId:pbId,url:url},function(json){
                                    // alert(JSON.stringify(json));
                                    if(json.status==1){
										var quantity=$('.quantity_span').text();
										var quantity=Number(quantity);
										var quantity=quantity+1;
										$('.quantity_span').text(quantity);
										$('.quantity').css('display','block');
                                        wstMsg('上传成功,图片已保存在右侧图片库');


                                    }else{
                                        wstMsg('上传失败，请重新上传');
                                    }

                                })
                            }
                        }
                    })

                 if(localIds.length > 0){
                     // setTimeout(syncUpload(localIds),100);
                     syncUpload(localIds)
                 }
            }
        });

    };
    function testLoad(localIds){
        var localId=localIds.pop();
        wx.getLocalImgData({
            localId: localId.toString(),
            isShowProgressTips: 1,
            success: function (res) {
                var localData = res.localData; // localData是图片的base64数据，可以用img标签显示
                localData = localData.replace('jgp', 'jpeg');
                $.ajax({
                    type:'POST',
                    url:'http://www.youyiku-yishu.cn/Test.php',
                    // url: U('WebApp/PhotoBooks/weChatUpload'),

                    data: {'imgData':localData},
                    dataType:'json',
                    success: function (data) {
                        // alert(JSON.stringify(data));
                        if(data.status==1){
                            var url=data.filepath;
                            var pbId=$('#pbId').val();
                            // console.log(pbId)
                            $.post(U('WebApp/PhotoBooks/uploadToImgDepot'),{pbId:pbId,url:url},function(json){
                                // alert(JSON.stringify(json));
                                if(json.status==1){
                                    var quantity=$('.quantity_span').text();
                                    var quantity=Number(quantity);
                                    var quantity=quantity+1;
                                    $('.quantity_span').text(quantity);
                                    $('.quantity').css('display','block');
                                    wstMsg('上传成功,图片已保存在右侧图片库');

                                }else{
                                    wstMsg('上传失败，请重新上传');
                                }

                            })
                        }
                    }
                })


            // alert(localData);
            if(localIds.length > 0){
                    setTimeout(testLoad(localIds),200);
                }
            },
            fail: function (res) {
                //alert('该图片暂时无法查看')
                // console.log(res);
            }
        })
    }









})

$('.previous').click(function(){
	var current_page=$('#current_page').val();
	var all_page=$('#all_page').val();
	console.log(all_page);
	$('.Span').html(current_page);
	$('.Span2').html(all_page);
	
})

/*
 *语音转二维码
 */
function erweima(url,obj){
    // var newurl='http://cheshi.youyiku-yishu.cn/'+url;
 var newurl='http://www.youyiku-yishu.cn/'+url;
    createErweima(newurl,obj);
    //需要qrjs2.min.js
    function createErweima(newurl,obj){
        //console.log(url,obj);
        var container1 = $(obj);
      
        var svgElement = document.createElement("div"),
            u = newurl,
            s = QRCode.generateSVG(u, {
                ecclevel: "M",
                fillcolor: "#FFFFFF",
                textcolor: "#373737",
                //						margin: 4,
                //						modulesize: 4
            });
        svgElement.appendChild(s);
        container1.append(svgElement);
        $('.text1').addClass('text1-wh');
        $('.text2').addClass('text2-wh');
        $('.text3').addClass('text3-wh');
        $('.text4').addClass('text4-wh');
        $('.text5').addClass('text5-wh');
        $('.text6').addClass('text6-wh');
        $('.text7').addClass('text7-wh');
        $(".FunctionBar").css('display','block');






      sounds();
    }
}

/*
 *加语音条
 */
function sounds(){
	      var page=$('.erWeiMa').html();
//	       console.log(page);
       page+='<img src="'+ROOT+'/Apps/WebApp/View/default/images/photoNewBook/yuyintiao.png" class="sounds"/>';
    $('.erWeiMa').html(page);
}
/*
 *网址变二维码
 */
function tobecode(){
    $(".erWeiMa").each(function(){
        var url = $(this).data("url");
        erweima(url,this);
    })
}

/*
 *在指定字符串插入
 */
function insert_flg(str,flg,sn){
    //要插入的字符

    var newstr="";
    for(var i=0;i<str.length;i+=sn){
        var tmp=str.substring(i, i+sn);
        newstr+=tmp+flg;
        flg='';
    }
    return newstr;
}
/*
 *删除一页
 */
function deletePage(){

    $('.bullet1').css('display','block');
    $('.shade4').css('display','block');


}

$('.bullet-quxiao').click(function(){
    $('.shade4').css('display','none');
    $('.bullet1').css('display','none');

})
/*
 *删除一页
 */
$('.bullet-queding').click(function(){
    var pbId=sessionStorage.getItem("pbId");
    var inPage=$('#current_page').val();
    var totalPage=$('#all_page').val();
    var master=$('#master').val();
    inPage=Number(inPage);
    totalPage=Number(totalPage);
       $.ajax({
		    type:"POST",
		    url:"http://www.youyiku-yishu.cn/WebApp/AppPhotoBooks/deleteCurrentPage",
		    data:{pbId:pbId,inPage:inPage,master:master},
		    dataType:"json",
		       beforeSend: function (XMLHttpRequest) {
		         		XMLHttpRequest.setRequestHeader("DEVICEINFO", "JxRaZezavm3HXM3d9pWnYiqqQC1SJbsU");
		       }
		  }).then(json=>{
    if(json.status==1){
        if(1<inPage && inPage==totalPage){
            //当前页为最后一页
            var nowPage = inPage-1;
            getPage(nowPage);
            $('#current_page').val(nowPage);
            $('#all_page').val(nowPage);
            $('.Span').html(nowPage);
            $('.Span2').html(nowPage);
            wstMsg('删除成功');
        }else if(inPage<totalPage){
            //整本书不止一页的情况
            var nowPage1=inPage;
            var nowPage2=totalPage-1;
            getPage(nowPage1);
            $('#current_page').val(nowPage1);
            $('#all_page').val(nowPage2);
            $('.Span').html(nowPage1);
            $('.Span2').html(nowPage2);
            wstMsg('删除成功');
            //整本书只剩一页
        }else if(inPage==1 && totalPage==1){
            $('.Conter').html('');
            wstMsg('删除成功,本书已空');
        }
     
         var imageData=json.count;
		   imageData=Number(imageData);
	    var quantity=$('.quantity_span').text();
		 quantity=Number(quantity);
		var quantity=quantity+imageData;
		$('.quantity_span').text(quantity);			
		$('.quantity').css('display','block');
		
    }else{
        wstMsg('您无权删除本页');
    }
		
		
		
    })
	    
    $('.shade4').css('display','none');
    $('.bullet1').css('display','none');

})

/*
 *提示信息
 */
function wstMsg(msg, focusTarget, time){
    $('#wst-modal-content').html(msg);
    $('#wst-msg-modal').show();
    $('#wst-msg-modal').addClass('am-animation-fade');
    var t = time ? time : 2;
    setTimeout(function(){
        if(focusTarget){
            $('#'+focusTarget).focus();
        }
        $('#wst-msg-modal').fadeOut(1000);
    },t*1000);
}

$('.thread-boundbook').click(function(){
	
	var pbId=$("#pbId").val();
	var master=$('#master').val();	
        master=Number(master);
	//判断是否为书主人
    if(master==0){
        wstMsg('您无此权限');
    }else{
        location.href = "../photoNewbook/coverpaper.html";
    }

	
	
})
/*
 *跳转预览页
 */
$('.accomplish').click(function(){
	$('.accomplish').addClass('boundbook');
	$('.Editcontent').removeClass('boundbook');
	$('.thread-boundbook').removeClass('boundbook');	
   				location.href ="preview.html"  
        
    
})


/*
 *旋转图片
 */
var num =0;
var degrees=0;
$('.xuanzhuan').click(function(){
    // console.log(111);
    var direction=$("#direction").val();
    var pbId=$('#pbId').val();
    var inPage= $('#current_page').val();
    num ++;
  // var c=  $(".targetObj_"+direction);
  //   console.log(c);
    $(".targetObj_"+direction).rotate(90*num);
    if(num%4==0){
        degrees=360;
        num=4;
    }
    else if(num%3==0){
         degrees=270;
         num=3;
    }
    else if(num%2==0){
       degrees=180;
       num=2;
    }else{
     degrees=90;
           num=1;
    }
    degrees=Number(degrees);
    $.post(Think.U('WebApp/PhotoBooks/saveRotation'),{transform:degrees,pbId:pbId,inPage:inPage,direction:direction}, function(json){
    	console.log(num);
//			alert(JSON.stringify(json));
        if(json.status==1){
            wstMsg("图片旋转成功");
//          $('.Uploadmode').css('display','none');
            $('.shade').css('display','none');
        }

    $('.Photolibrary').css('display','none');//防止误触图片库
$('#remove').val(0);
    })

})
//移动位置保存
   function Position(){
	 	var pbId=$("#pbId").val();
	     var inPage=$("#current_page").val();
       var direction=$('#direction').val();
	 	// for(var i=1;i<=5;i++){
	 		var Obj_1=$('.targetObj_'+direction).css('transform');
	 		if(Obj_1!=undefined && Obj_1!="none"){
	 		var Obj_1=$('.targetObj_'+direction).css('transform');
	 		var Obj_2=$('.targetObj_'+direction).css('transform-origin');
	 	
	 		var str=Obj_1
	 
	 		var str1=str.slice(7,-1);
	 		// console.log(str1);
	 		var arr=new Array();
	 		arr=str1.split(',');
	 		var st1=arr[0];
	 		var st2=arr[4];
	 		var st3=arr[5];
	 		var page="";
	 		var num=$('#imgbox').val();
	 		// console.log(st1,st2,st3);

	 		var img1=$('.targetObj_'+direction).attr('src');
            var page=$('.targetObj_'+direction).prop("outerHTML");
	 		// page+='<img src="'+img1+'" onclick="photoedit('+direction+')"class="mw targetObj_'+direction+' " id="" style="position: relative; transform-origin: 0px 0px 0px; left: 0px; transition: all 0.5s ease-out; cursor: move; visibility: visible; transform: translate3d('+st2+'px,'+st3+'px, 0px) scale3d('+st1+', '+st1+', 1);"/>';
            page+='<div class="upload-div""></div>';
            console.log(page)
	 		$('.img'+num).html(page);
	 		 $.post(Think.U('WebApp/PhotoBooks/saveDirection'),{pbId:pbId,page:inPage,direction:direction,ratio:st1,left:st2,top:st3},function(json){
	               // console.log(json);
	               })
	 	   }
	   // var file='<input type="file" name="fileV" id="fileV" class="fileV ffff">';
	   //  $('.btnn').html(file);
       // var data=$('.img'+num).attr('data');
       // var transform=$('.img'+num).css('transform','rotate('+data+'deg)');
       $('.previous').css('display','block');
       $('.next').css('display','block');
	 	// }
	 }
//大图片库
function warehouse_div_img(param,i){
	var data=$(param).attr('data');
	data=Number(data);
	if(data==1){
		$(param).attr('data','0');
	}else if(data==0){
		$(param).attr('data','1');
	}
	
	$(".wx"+i).toggle()
	$(".xz"+i).toggle()
}
function xl(){
	$('.warehouse_img').css('display','none');
}
$('.warehouse').click(function(){
	$('.pagination').css('display','none');
	$('.warehouse_img').css('display','inline');
	var userId=sessionStorage.getItem('userId');
    var pbId=sessionStorage.getItem('pbId');	
     $.ajax({
		    type:"POST",
		    url:"http://www.youyiku-yishu.cn/WebApp/AppPhotoBooks/newPicDepot",
		    data:{pbId:pbId,userId:userId},
		    dataType:"json",
		       beforeSend: function (XMLHttpRequest) {
		         		XMLHttpRequest.setRequestHeader("DEVICEINFO", "JxRaZezavm3HXM3d9pWnYiqqQC1SJbsU");
		       }
		  }).then(json=>{
        var page="";
        var flg='_thumb';
        if(json){
            for(var i=0;i<json.length;i++){
                var imgage=json[i].img;
                var img1=insert_flg(imgage,flg,37);
                page+='<div class="warehouse_div_img warehouse_div_img_'+json[i].photoId+'" onclick="warehouse_div_img(this,'+json[i].photoId+')" data="" photoBookId="'+json[i].photoId+'">';
                page+='<img src="'+ROOT+'/'+img1+'" alt=""  class="print"/>';
                page+='<img src="'+ROOT+'/Apps/WebApp/View/default/images/photoNewBook/wx.png" alt=""  class="wx wx_'+json[i].photoId+'"/>';
                page+='<img src="'+ROOT+'/Apps/WebApp/View/default/images/photoNewBook/xz.png" alt=""  class="xz xz'+json[i].photoId+'"/>';
                page+='</div>';
            }
        }

        $('.warehouse_div_1').html(page);

//$('.pageturning').attr('data','1');
//	$('.previous').css('display','none');
//	$('.next').css('display','none');
    })
})

//删除选中的图片
function sctp(){
imageData=new Array();

$('.warehouse_div_img').each(function(){
        var data=($(this).attr('data'));
        if(data==1){
            var photoBookId=($(this).attr('photoBookid'))
			
            imageData.push(photoBookId);
            // console.log($('.warehouse_div_img_'+photoBookId));
            $('.warehouse_div_img_'+photoBookId).remove();
        }
		
    })
//将选中的图片组装成一个字符串，用','隔开
    var photoBookIds=imageData.join(",");
    // $.post(U('WebApp/PhotoBooks/deletePic'),{photoBookIds:photoBookIds},function(json) {
    //
    // })
    var pbId=sessionStorage.getItem('pbId');
     $.ajax({
		    type:"POST",
		    url:"http://www.youyiku-yishu.cn/WebApp/AppPhotoBooks/deletePic",
		    data:{pbId:pbId,photoBookIds:photoBookIds},
		    dataType:"json",
		       beforeSend: function (XMLHttpRequest) {
		         		XMLHttpRequest.setRequestHeader("DEVICEINFO", "JxRaZezavm3HXM3d9pWnYiqqQC1SJbsU");
		       }
		  }).then(json=>{
		  })
	var imageLenth=imageData.length;
		var quantity=$('.quantity_span').text();
		var quantity=Number(quantity);
		var quantity=quantity-imageLenth;
		$('.quantity_span').text(quantity);
        if(quantity==0){
			$('.quantity').css('display','none');
		}
}
/*
 *选择图片放在书本上
 */
function uploadToPage(){
    imageData=new Array();
    $('.warehouse_div_img').each(function(){
        var data=($(this).attr('data'));
        if(data==1){
            var photoBookId=($(this).attr('photoBookid'))

            imageData.push(photoBookId);
            // console.log($('.warehouse_div_img_'+photoBookId));
            $('.warehouse_div_img_'+photoBookId).remove();
        }
		
    })

    var photoIds=imageData.join(",");
     var pbId=sessionStorage.getItem('pbId');
    $.ajax({
        type:'GET',
        url:"http://www.youyiku-yishu.cn/WebApp/AppPhotoBooks/newComposing",

        data: {photoIds:photoIds,pbId:pbId},
        dataType:'json',
             beforeSend: function (XMLHttpRequest) {
		         		XMLHttpRequest.setRequestHeader("DEVICEINFO", "JxRaZezavm3HXM3d9pWnYiqqQC1SJbsU");
		       }
		  }).then(json=>{
		  	    var inPage=json.inPage;
		  	    var page=json.inPage;
                var page1=Number(page);
		        $('#current_page').val(page1);
                $('#all_page').val(page1);
                $('.Span').html(page1);
                $('.Span2').html(page1);
                  getPage(page1);
		  })
		var imageData=imageData.length;
		var quantity=$('.quantity_span').text();
		var quantity=Number(quantity);
		var quantity=quantity-imageData;
		$('.quantity_span').text(quantity);
		if(quantity==0){
			$('.quantity').css('display','none');
		}
}
/*
 *一键排版
 */
function newCompose(){
    imageData=new Array();

    $('.warehouse_div_img').each(function(){

            var photoBookId=($(this).attr('photoBookid'))

            imageData.push(photoBookId);
            $('.warehouse_div_img_'+photoBookId).remove();


    })

    var photoIds=imageData.join(",");
    // console.log(photoBookIds);
         var pbId=sessionStorage.getItem('pbId');
         var userId=sessionStorage.getItem('userId');
    $.ajax({
        type:'GET',
        url:"http://www.youyiku-yishu.cn/WebApp/AppPhotoBooks/timeComposing",

        data: {photoIds:photoIds,pbId:pbId,userId:userId},
        dataType:'json',
             beforeSend: function (XMLHttpRequest) {
		         		XMLHttpRequest.setRequestHeader("DEVICEINFO", "JxRaZezavm3HXM3d9pWnYiqqQC1SJbsU");
		       }
		  }).then(data=>{
            if(data.status==1){
                var page=data.inPage;
                var page1=Number(page);
                $('#current_page').val(page1);
                $('#all_page').val(page1);
                $('.Span').html(page1);
                $('.Span2').html(page1);
                getPage(page1);
            }  
    })

		$('#quantity').val('0');
        $('.quantity_span').text('0');		
		$('.quantity').css('display','none');
		$('.warehouse_img').css('display','none');
		

}
$('.Transfer3').click(function(){
	$('.mouldpage').css('display','inline');
	$('.pagination').css('display','none');
})
$('.Transfer2').click(function(){
	$('.Photolibrary1').css('display','inline');
	$('.pagination').css('display','none');
})
$('.Transfer').click(function(){
	$('.mouldpage').css('display','none');
})
//页面内容互换
$('.Transfer4').click(function(){
	var data=$('.Transfer4').attr('data');
	data=Number(data);
	// console.log(data);
	if(data==1){
		$('.Transfer4').attr('data','0');
			$('.pagination').css('display','block');
	}else if(data==0){
		$('.Transfer4').attr('data','1');
			$('.pagination').css('display','none');
	}
})

$('.pag_div').click(function(){
	$('.pagination').css('display','none');
	var i1=$('.pag_input1').val();
	var i2=$('.pag_input2').val();
    var inPage=$('#current_page').val();
    var totalPage=$('#all_page').val();
    var pbId=sessionStorage.getItem('pbId');
    i1=Number(i1);
    i2=Number(i2);    
    if(i1<=0 || i2<=0){
        wstMsg('所选页码不能为0');
    }else if(i1>totalPage || i2>totalPage){
        wstMsg('所选页码不能超过最大页码值');
    }else{
        // console.log(i1,i2);
        $.ajax({
            type:'GET',
            url: "http://www.youyiku-yishu.cn/WebApp/AppPhotoBooks/exchangePage",
            data: {'previousPag':i1,'backPage':i2,'pbId':pbId},
            dataType:'json',
            beforeSend: function (XMLHttpRequest){
		         		XMLHttpRequest.setRequestHeader("DEVICEINFO", "JxRaZezavm3HXM3d9pWnYiqqQC1SJbsU");
		       }
            }).then(data=>{
                console.log(data);
                console.log(i1,i2)
           		inPage=Number(inPage);
           		if(i1==inPage){
           			getPage(i1);
           			$('.Span').text(i1);
           		}else if(i2==inPage){
           			getPage(i2);
           				$('.Span').text(i2);
           				$('#currPage').val(i2);
           			
           		}else{
           			getPage(i1);
           				$('.Span').text(i1);
           				$('#currPage').val(i1);
           		}
                $('.pag_input1').val('');
				$('.pag_input2').val('');    
        })
	}
	
})
$('.Conter').click(function(){
	$('.pagination').css('display','none');
})
$('.Editcontent').click(function(){
//	 location.href ="../photoNewBook/templet.html"
})
//$('.btn-old').click(function(){
//	 $('.warn_1').css('display','block');
//})
$('.bullet-quxiao').click(function(){
	$('.bullet1').css('display','none');
})

